﻿Imports MeoTom.Core

Namespace Control

    Partial Public Class CommentReply
        Inherits UserControl
        Public Cm As New BLL.Comments()
        Public Util2 As New Utilities.Common()

        Protected Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs) Handles Me.Load
            If Not IsPostBack Then
                Dim previousPage As String = ""
                If Request.QueryString.ToString = vbNullString Then
                    previousPage = Server.UrlEncode(Request.ServerVariables("PATH_INFO"))
                Else
                    previousPage = Server.UrlEncode(Request.ServerVariables("PATH_INFO") & "?" & Request.QueryString.ToString())
                End If
                Util2.ValidateLogin(previousPage)

                Dim strUser As String
                Dim strEmail As String

                Cm.CommentsID = Integer.Parse(Request.QueryString("CommentsID"))
                Cm.GetByID()
                If Util2.GetCookie("UserName") = "" Then
                    strUser = Util2.GetSession("UserName")
                    strEmail = Util2.GetSession("Email")
                Else
                    strUser = Util2.GetCookie("UserName")
                    strEmail = Util2.GetCookie("Email")
                End If
                txtBody.Value = "<b>@" & Cm.AddedBy & ": </b>"
                txtEmail.Text = strEmail
                txtName.Text = strUser
            End If
        End Sub

        Private Sub btnCancel_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnCancel.Click
            Response.Redirect("/mt-inside/ArticleComment.aspx")
        End Sub

        Private Sub btnReply_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnReply.Click
            cm.AddedByEmail = txtEmail.Text
            Cm.AddedBy = txtName.Text
            cm.AddedByIP = Request.UserHostAddress.ToString()
            cm.Body = txtBody.Value
            cm.ArticleId = Integer.Parse(Request.QueryString("ArticlesId"))
            cm.AddedByURL = txtURL.Text
            cm.Create()
            cm.WriteAricleComment(0)
            Response.Redirect("/mt-inside/ArticleComment.aspx")
        End Sub
    End Class
End Namespace